//
//  HYMeetingRoomInfoView.m
//  Booking
//
//  Created by Maybe_文仔 on 2018/7/27.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMeetingRoomInfoView.h"

@interface HYMeetingRoomInfoView()
@property (nonatomic, strong) UIImageView *roomImgView;
@property (nonatomic, strong) UILabel *roomLab;
@property (nonatomic, strong) UILabel *capacityLab;
@property (nonatomic, strong) UILabel *extensionLab;
@property (nonatomic, strong) UIButton *bookingBtn;
@end

@implementation HYMeetingRoomInfoView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [KAPP_WHITE_COLOR colorWithAlphaComponent:0.8];
        [self setupSubViews];
    }
    return self;
}

-(void)setupSubViews{
    [self addSubview:self.roomImgView];
    [self addSubview:self.roomLab];
    [self addSubview:self.capacityLab];
    [self addSubview:self.extensionLab];
    [self addSubview:self.bookingBtn];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    [self.roomImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(10*WIDTH_MULTIPLE);
        make.size.mas_equalTo(CGSizeMake(110*WIDTH_MULTIPLE, 79*WIDTH_MULTIPLE));
    }];
    
    [self.roomLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.roomImgView.mas_top);
        make.left.equalTo(self.roomImgView.mas_right).offset(10*WIDTH_MULTIPLE);
    }];
    
    [self.extensionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.roomImgView.mas_bottom);
        make.left.equalTo(self.roomLab.mas_left);
    }];
    
    [self.capacityLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.extensionLab.mas_top).offset(-8*WIDTH_MULTIPLE);
        make.left.equalTo(self.roomLab.mas_left);
    }];
    
    [self.bookingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-10*WIDTH_MULTIPLE);
        make.size.mas_equalTo(CGSizeMake(68*WIDTH_MULTIPLE, 34*WIDTH_MULTIPLE));
    }];
}

-(void)setRoomModel:(HYMeetingRoomModel *)roomModel{
    _roomModel = roomModel;
    [self.roomImgView sd_setImageWithURL:[NSURL URLWithString:roomModel.imgUrl] placeholderImage:[UIImage imageNamed:@"image_placeholder"]];
    self.roomLab.text = roomModel.name;
    self.capacityLab.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"capacity", nil),roomModel.capacity];
    self.extensionLab.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"tel", nil),roomModel.tel];
}

-(void)bookAction{
    if (self.bookRoomBlock) {
        self.bookRoomBlock(self.roomModel);
    }
}

#pragma mark - lazyload

-(UIImageView *)roomImgView{
    if (!_roomImgView) {
        _roomImgView = [[UIImageView alloc]init];
        _roomImgView.layerCornerRadius = 4.0;
    }
    return _roomImgView;
}

-(UILabel *)roomLab{
    if (!_roomLab) {
        _roomLab = [[UILabel alloc]init];
        _roomLab.textColor = RGBColor(51, 51, 51);
        _roomLab.font = KFitFont(20);
    }
    return _roomLab;
}

-(UILabel *)capacityLab{
    if (!_capacityLab) {
        _capacityLab = [[UILabel alloc]init];
        _capacityLab.textColor = RGBColor(102, 102, 102);
        _capacityLab.font = KFitFont(14);
        _capacityLab.text = NSLocalizedString(@"capacity", nil);
    }
    return _capacityLab;
}

-(UILabel *)extensionLab{
    if (!_extensionLab) {
        _extensionLab = [[UILabel alloc]init];
        _extensionLab.textColor = RGBColor(102, 102, 102);
        _extensionLab.font = KFitFont(14);
        _extensionLab.text = NSLocalizedString(@"tel", nil);
    }
    return _extensionLab;
}

-(UIButton *)bookingBtn{
    if (!_bookingBtn) {
        _bookingBtn = [[UIButton alloc]init];
        [_bookingBtn setTitle:NSLocalizedString(@"book", nil) forState:(UIControlStateNormal)];
        _bookingBtn.titleLabel.textColor = KAPP_WHITE_COLOR;
        _bookingBtn.backgroundColor = KAPP_THEME_COLOR;
        _bookingBtn.titleLabel.font = KFitFont(18);
        _bookingBtn.layerCornerRadius = 5.0;
        [_bookingBtn addTarget:self action:@selector(bookAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _bookingBtn;
}


@end
